#if !GENERATOR


#region Imported Namespaces



using System.Collections.Generic;


#endregion


namespace YF.OneNote.DataTypes
{
  using Collections;


  public partial class Page
  {
    #region Constructors/Finalizers



    public Page()
    {
      _items.CollectionChanged += _items_CollectionChanged;
      _meta.CollectionChanged += _meta_CollectionChanged;
      _tagDef.CollectionChanged += _tagDef_CollectionChanged;
    }



    #endregion


    #region Methods



    private void _items_CollectionChanged(object sender, NotifyCollectionChangedEventArgs<PageObject> e)
    {
      switch (e.Action)
      {
        case NotifyCollectionChangedAction.Add:
        {
          foreach (PageObject item in e.NewItems)
            Children.Add(item);
        }
          break;

        case NotifyCollectionChangedAction.Remove:
        {
          foreach (PageObject item in e.OldItems)
            Children.Remove(item);
        }
          break;
      }
    }


    private void _meta_CollectionChanged(object sender, NotifyCollectionChangedEventArgs<Meta> e)
    {
      switch (e.Action)
      {
        case NotifyCollectionChangedAction.Add:
        {
          foreach (Meta item in e.NewItems)
            Children.Add(item);
        }
          break;

        case NotifyCollectionChangedAction.Remove:
        {
          foreach (Meta item in e.OldItems)
            Children.Remove(item);
        }
          break;
      }
    }


    private void _tagDef_CollectionChanged(object sender, NotifyCollectionChangedEventArgs<TagDef> e)
    {
      switch (e.Action)
      {
        case NotifyCollectionChangedAction.Add:
        {
          foreach (TagDef item in e.NewItems)
            Children.Add(item);
        }
          break;

        case NotifyCollectionChangedAction.Remove:
        {
          foreach (TagDef item in e.OldItems)
            Children.Remove(item);
        }
          break;
      }
    }


    protected override bool UpdateSpecificContents(NotesHierarchyNode node, List<INotesChange> changes)
    {
      Page item = (Page)node;
      bool changed = false;

      if (DateTime != item.DateTime)
      {
        changed = true;

        NotesPropertyChange propertyChange = new NotesPropertyChange();

        propertyChange.ChangeType = NoteChangeType.Changed;
        propertyChange.OldValue = _dateTime;
        propertyChange.NewValue = item._dateTime;
        propertyChange.PropertyName = "DateTime";
        changes.Add(propertyChange);

        _dateTime = item._dateTime;
      }

      if (_updateContents)
      {
        if (IsCurrentlyViewed != item.IsCurrentlyViewed)
        {
          changed = true;

          NotesPropertyChange propertyChange = new NotesPropertyChange();

          propertyChange.ChangeType = NoteChangeType.Changed;
          propertyChange.OldValue = _isCurrentlyViewed;
          propertyChange.NewValue = item._isCurrentlyViewed;
          propertyChange.PropertyName = "IsCurrentlyViewed";
          changes.Add(propertyChange);

          _isCurrentlyViewed = item._isCurrentlyViewed;
        }

        if (IsIndexed != item.IsIndexed)
        {
          changed = true;

          NotesPropertyChange propertyChange = new NotesPropertyChange();

          propertyChange.ChangeType = NoteChangeType.Changed;
          propertyChange.OldValue = _isIndexed;
          propertyChange.NewValue = item._isIndexed;
          propertyChange.PropertyName = "IsIndexed";
          changes.Add(propertyChange);

          _isIndexed = item._isIndexed;
        }

        if (IsSubPage != item.IsSubPage)
        {
          changed = true;

          NotesPropertyChange propertyChange = new NotesPropertyChange();

          propertyChange.ChangeType = NoteChangeType.Changed;
          propertyChange.OldValue = _isSubPage;
          propertyChange.NewValue = item._isSubPage;
          propertyChange.PropertyName = "IsSubPage";
          changes.Add(propertyChange);

          _isSubPage = item._isSubPage;
        }

        if (Lang != item.Lang)
        {
          changed = true;

          NotesPropertyChange propertyChange = new NotesPropertyChange();

          propertyChange.ChangeType = NoteChangeType.Changed;
          propertyChange.OldValue = _lang;
          propertyChange.NewValue = item._lang;
          propertyChange.PropertyName = "Lang";
          changes.Add(propertyChange);

          _lang = item._lang;
        }

        if (PageSettings != item.PageSettings)
        {
          changed = true;

          NotesPropertyChange propertyChange = new NotesPropertyChange();

          propertyChange.ChangeType = NoteChangeType.Changed;
          propertyChange.OldValue = _pageSettings;
          propertyChange.NewValue = item._pageSettings;
          propertyChange.PropertyName = "PageSettings";
          changes.Add(propertyChange);

          _pageSettings = item._pageSettings;
        }

        if (Selected != item.Selected)
        {
          changed = true;

          NotesPropertyChange propertyChange = new NotesPropertyChange();

          propertyChange.ChangeType = NoteChangeType.Changed;
          propertyChange.OldValue = _selected;
          propertyChange.NewValue = item._selected;
          propertyChange.PropertyName = "Selected";
          changes.Add(propertyChange);

          _selected = item._selected;
        }

        if (Style != item.Style)
        {
          changed = true;

          NotesPropertyChange propertyChange = new NotesPropertyChange();

          propertyChange.ChangeType = NoteChangeType.Changed;
          propertyChange.OldValue = _style;
          propertyChange.NewValue = item._style;
          propertyChange.PropertyName = "Style";
          changes.Add(propertyChange);

          _style = item._style;
        }

        if (Title != item.Title)
        {
          changed = true;

          NotesPropertyChange propertyChange = new NotesPropertyChange();

          propertyChange.ChangeType = NoteChangeType.Changed;
          propertyChange.OldValue = _title;
          propertyChange.NewValue = item._title;
          propertyChange.PropertyName = "Title";
          changes.Add(propertyChange);

          _title = item._title;
        }

        if (UpdateCollection(Items, item.Items, changes))
          changed = true;

        if (UpdateCollection(Meta, item.Meta, changes))
          changed = true;

        if (UpdateCollection(TagDef, item.TagDef, changes))
          changed = true;
      }

      return changed;
    }



    #endregion
  }
}


#endif